package com.Controller;
import com.Service.PersonalIndexService;
import com.pojo.PersonalIndex;
import com.pojo.PersonalRemark;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping("/myIndex")
public class PersonalIndexController {
    @Autowired
    private PersonalIndexService personalIndexService;
    @GetMapping("/message")
    public ModelAndView loadMessage(String username) throws SQLException {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("personalIndex");
        List<PersonalIndex> personalIndices=personalIndexService.findMyMessage(username);
        modelAndView.addObject("personalMessage",personalIndices);
        return modelAndView;
    }
    @GetMapping("/myRemark")
    @ResponseBody
    public List<PersonalRemark> getMyRemark(String username) throws SQLException {
        return personalIndexService.getMyRemark(username);
    }
    @PostMapping("/newNickName")
    @ResponseBody
    public void updateMyNickName(@RequestParam String username,@RequestParam String newNickName) throws SQLException {
      personalIndexService.updateMyNickName(username,newNickName);
    }
}
